package com.example.controller;

import com.example.entity.MedicalInstitution;
import com.example.service.MedicalInstitutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/medicalInstitution")
public class MedicalInstitutionController {

    @Autowired
    private MedicalInstitutionService medicalInstitutionService;

    // 创建医疗机构
    @PostMapping("/add")
    public String addMedicalInstitution(@RequestBody MedicalInstitution institution) {
        System.out.println(institution);
        medicalInstitutionService.addMedicalInstitution(institution);
        return "医疗机构创建成功";
    }

    // 根据ID查询医疗机构
    @GetMapping("/get/{id}")
    public MedicalInstitution getMedicalInstitutionById(@PathVariable int id) {
        return medicalInstitutionService.getMedicalInstitutionById(id);
    }

    // 查询所有医疗机构
    @GetMapping("/all")
    public List<MedicalInstitution> getAllMedicalInstitutions() {
        return medicalInstitutionService.getAllMedicalInstitutions();
    }

    // 更新医疗机构信息
    @PutMapping("/update")
    public String updateMedicalInstitution(@RequestBody MedicalInstitution institution) {
        medicalInstitutionService.updateMedicalInstitution(institution);
        return "医疗机构信息更新成功";
    }

    // 删除医疗机构
    @DeleteMapping("/delete/{id}")
    public String deleteMedicalInstitution(@PathVariable int id) {
        medicalInstitutionService.deleteMedicalInstitution(id);
        return "医疗机构删除成功";
    }
}
